forked from aec-coding-club/AEC-Coding-Club-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Admin.jsx
79 lines (72 loc) · 2.3 KB
/
Admin.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { useEffect, useState } from "react";
import axios from "axios";
import { Api } from "../../../../backend";
import { NavLink, Outlet, useNavigate } from "react-router-dom";
import Base from "../../../../Base";
import "./Styles/admin-index.css";
const Admin = ({ userImage, userNameText }) => {
const [userId, setUserId] = useState(null);
const navigate = useNavigate();
const fetchLogs = async () => {
// Check Role for redirects
const token = localStorage.getItem("token");
if (!token) window.location = "/";
const parseddata = await axios.get(`${Api}dashboard`, {
withCredentials: true,
headers: { Authorization: `Bearer ${token}` },
});
if (!parseddata) navigate("/");
setUserId(parseddata.data.user_data.uid);
if (parseddata.data.user_data.role <= 2) navigate("/dashboard");
};
useEffect(() => {
fetchLogs();
}, []);
return (
<>
<Base>
<div className="admin-details">
<div className="left">
<img
src={userImage}
alt="user-image"
className="admin-user-img logged-user-image"
/>
<div className="user-details">
<p className="logged-user logged-user-text">
{/* <span>Name: </span> */}
{userNameText}
</p>
<p className="logged-user logged-user-id">
{/* <span>UID: </span> */}
<span className="admin-uid">
{userId ? userId : "Loading..."}
</span>
</p>
</div>
</div>
<h2>Welcome to Admin Panel</h2>
</div>
<div className="admin-nav">
<NavLink to="/admin/overview" className="admin-nav-link">
Overview
</NavLink>
<NavLink to="/admin/admin-users" className="admin-nav-link">
Users
</NavLink>
<NavLink to="/admin/admin-events" className="admin-nav-link">
Events
</NavLink>
<NavLink to="/admin/admin-logs" className="admin-nav-link">
Logs
</NavLink>
<NavLink to="/admin/admin-stats" className="admin-nav-link">
Stats
</NavLink>
</div>
<Outlet />
</Base>
</>
);
};
export default Admin;